package com.zhuoyue.web.controller.common;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author robin
 * @ClassName: ActionResult
 * @Description: action层向页面返回的信息(原商品通用的返回)
 * @date 2013-11-20 上午11:27:04
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ControllerApiResult<T> implements Serializable {

    private static final long serialVersionUID = 161389017990134747L;

    // 操作结果标志
    private boolean success;

    // 返回信息
    private String msg;

    // service层返回对象
    private Object dataObject;

    // 消息code
    private String msgCode;


    /**
     * 返回数据dataObject
     *
     * @param dataObject
     * @return
     */
    public static ControllerApiResult toReturnDataSuccess(String msg, Object dataObject) {
        return new ControllerApiResult(true, msg, dataObject, ResultApiCode.SUCCESS);

    }

    /**
     * 不返回数据只返回msg
     *
     * @param msg
     * @return
     */
    public static ControllerApiResult toReturnMessageSuccess(String msg) {
        return new ControllerApiResult(true, msg, null, ResultApiCode.SUCCESS);
    }

    public static ControllerApiResult toSysErrorFail(String msg) {
        return new ControllerApiResult(false, msg, null, ResultApiCode.SYS_ERROR);
    }

    /**
     * 参数错误
     *
     * @param msg
     * @return
     */
    public static ControllerApiResult toParamFail(String msg) {
        return new ControllerApiResult(false, msg, null, ResultApiCode.PARAM_ERROR);
    }

    /**
     * 查询无数据
     *
     * @param msg
     * @return
     */
    public static ControllerApiResult toNoDataFail(String msg) {
        return new ControllerApiResult(false, msg, null, ResultApiCode.NO_DATA);
    }

    /**
     * 自定义失败返回
     *
     * @param msg
     * @param msgCode
     * @return
     */
    public static ControllerApiResult toOtherFail(String msg, String msgCode) {
        return new ControllerApiResult(false, msg, null, msgCode);
    }

    public static ControllerApiResult toFail(String msg) {
        return new ControllerApiResult(false, msg, null, ResultApiCode.FAIL);
    }

    /**
     * token过期
     *
     * @param msg
     * @return
     */
    public static ControllerApiResult toTokenExpiret(String msg) {
        return new ControllerApiResult(false, msg, null, ResultApiCode.TOKEN_EXPIRET);
    }


}
